import java.util.Iterator;
import java.util.List;

public class Tool {
    public static double getAvg(List<Student> list) {//求平均值
        double sum = 0;
        Iterator<Student> iterator = list.iterator();
        while (iterator.hasNext()) {
            Student stu = iterator.next();
            sum += stu.getsJava();
        }
        return sum / list.size();
    }

    public static Student getMax(List<Student> list) {//求最大值

        Iterator<Student> iterator = list.iterator();
        Student stuMax=iterator.next();
        for (Student stu:list) {
            if (stu.getsJava() > stuMax.getsJava() ) {
                stuMax = stu;
            }
        }
     /*   Iterator<Student> iterator = list.iterator();
        double stuMax=list.get(0).getsJava();
        Student student=new Student();
        for (Student stu:list){
            if(stu.getsJava() > stuMax){
                stuMax=stu.getsJava();
                student=stu;
            }
        }*/


        return stuMax;

    }

    public static Student getMin(List<Student> list) {//求最小值
        Iterator<Student> iterator = list.iterator();
        Student stuMin=iterator.next();
        for (Student stu:list) {
            if (stu.getsJava() < stuMin.getsJava() ) {
                stuMin = stu;
            }
        }
        return stuMin;

    }
}
